/**
 * Copyright (C) 2012 The SkyTvOS Project
 * <p/>
 * Version     Date           Author
 * ─────────────────────────────────────
 * 2015年4月22日         luwei
 */

package com.tianci.appstore.ui.control;

import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;

import com.coocaa.x.framework.utils.Android;
import com.coocaa.x.framework.utils.LogUtils;
import com.paster.util.JsonUtil;
import com.tianci.appstore.ui.widget.SkyGridAdapter;

import org.json.JSONException;

import java.util.HashMap;

public class MoreManageController extends SkyMyAppController {

    public MoreManageController(Context context) {
        super(context);
    }

    @Override
    public String getScene() {
        return "com.tianci.appstore:MoreManageActivity";
    }

    @Override
    public boolean exeCommand(Intent intent) {
        if (intent.hasExtra("_scene")
                && intent.getStringExtra("_scene").equals(
                getScene())) {
            if (intent.hasExtra("_command")) {
                String command = intent.getStringExtra("_command");
                LogUtils.d("luwei", "the command is " + command);
                Android.simulateKey(KeyEvent.KEYCODE_BACK, 0);
                if (!((SkyGridAdapter) getCurrentPage().getAdapter()).audioMatch(command)) {
                    return super.exeCommand(intent);
                }
            }
        }
        return false;
    }

    @Override
    public String getCommand() {
        String json = "";
        HashMap<String, String[]> command = getGlobalCommand();
        addItemCommand(command);
        try {
            json = JsonUtil.makeScenceJson(
                    getScene(), command, null, null)
                    .toString();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return json;
    }
}
